<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('卡号')">
              <a-input :placeholder="$t('请输入卡号')" v-model="queryParam.cardSn"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('类型')">
              <j-dict-select-tag
                :placeholder="$t('请选择类型')"
                v-model="queryParam.type"
                dictCode="bis_member_coin.type"
              />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('状态')">
                <j-dict-select-tag
                  :placeholder="$t('请选择状态')"
                  v-model="queryParam.state"
                  dictCode="bis_member_coin.state"
                />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
              }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" 
      v-has="'BisMemberCoinController:export'" icon="download" @click="handleExportXls($t('数字币账户'))">{{ $t('导出') }}</a-button>
      <a-button type="primary" 
        v-has="'BisMemberCoinController:cancel'" @click="ManualCancel">{{ $t('人工注销') }}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="rowSelection"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="footer">
          <div style="font-weight: bold">
            <span>{{ $t('总币值') }}：{{ totalInfo.value }}</span>
          </div>
        </template>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { postAction } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'BisMemberCoinList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  data() {
    return {
      description: this.$t('数字币账户管理页面'),
      // 表头
      columns: [
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'cardSn',
        },
        {
          title: this.$t('类型'),
          align: 'center',
          dataIndex: 'type_dictText',
        },
        {
          title: this.$t('状态'),
          align: 'center',
          dataIndex: 'state_dictText',
        },
        {
          title: this.$t('币值'),
          align: 'center',
          dataIndex: 'value',
        },
      ],
      url: {
        list: '/coin/bisMemberCoin/list',
        delete: '/coin/bisMemberCoin/delete',
        deleteBatch: '/coin/bisMemberCoin/deleteBatch',
        exportXlsUrl: '/coin/bisMemberCoin/exportXls',
        importExcelUrl: 'coin/bisMemberCoin/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      totalCallback: this.totalCallbacks,
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    rowSelection() {
      let _this = this
      const { selectedRowKeys } = this
      return {
        selectedRowKeys,
        onChange: (selectedRowKeys, selectionRows) => {
          _this.onSelectChange(selectedRowKeys, selectionRows)
        },
        getCheckboxProps: (record) => ({
          props: {
            // 全部默认禁止选中
            // disabled: true,
            // 某几项默认禁止选中(R: 当state等于1时)
            disabled: record.state == '1', // 某几项默认选中(R: 当state等于1时) // defaultChecked: record.state == 1,
          },
        }),
      }
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'cardSn', text: '卡号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'type', text: '类型', dictCode: 'bis_member_coin.type' })
      fieldList.push({ type: 'string', value: 'state', text: '状态', dictCode: 'bis_member_coin.state' })
      fieldList.push({ type: 'BigDecimal', value: 'value', text: '币值', dictCode: '' })
      this.superFieldList = fieldList
    },
    totalCallbacks(totalInfo) {
      this.totalInfo = totalInfo
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
    ManualCancel() {
      let that = this
      if (that.selectedRowKeys.length == 0) {
        return
      }
      that.$confirm({
        title: that.$t('提示'),
        content: that.$t('注销后该币将作废不可用，您确定要进行注销吗？'),
        okText: that.$t("确定"),
        cancelText: that.$t("取消"),
        onOk: function () {
          let list=[]
          that.selectionRows.forEach(ele => {
            list.push({
              memberCoin:{
                cardSn: ele.cardSn
              }
            })
          });
          postAction('/trans/trans', {
            order: { typeId: 97 },
            orderGoodsList: list,
          }).then((res2) => {
            if (res2.success) {
              that.$message.success(res2.message)
              that.loadData(that.ipagination.current)
              that.selectedRowKeys = []
              that.selectionRows = []
            } else {
              that.$message.error(res2.message)
            }
          })
        },
        onCancel() {},
      })
      console.log(this.selectionRows)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>